This is a Jupyter notebook

The purpose of this notebook is to get you started with Jupyter notebooks. This notebook is a step-by-step guide for downloading, installing, and running Jupyter.

This notebook was originally created for a Digital Mixer session at the 2016 STELLA Unconference

What are Jupyter Notebooks?

The Jupyter Notebook is a browser-based, open-source tool for sharing...

interactive code,...


In [1]:
print("This is a line of code.")


This is a line of code.

visualizations,...


In [4]:
from matplotlib import pyplot as plt
import numpy as np
%matplotlib inline
plt.style.use('ggplot')
x = np.linspace(0, 2*np.pi)
plt.ylim(-1.1, 1.1)
plt.xlim(-0.1, 2*np.pi + 0.1)
plt.plot(x,[np.sin(y) for y in x], "or")


Out[4]:
[<matplotlib.lines.Line2D at 0x11240d898>]

and explanatory text in over 40 programming languages. Jupyter notebooks are used for everything from data exploration and computational analyses to information presentation and interactive instructional materials for mathematical, statistical, and programming concepts. They are applicable across varied fields and are popular within data sciences, scientific computing, and education.

In addition to the uses for the combined writing of code and rich text, Jupyter notebooks are easily sharable via email, cloud storage services, nbViewer or GitHub. In particular, GitHub provides storage and rendering of Jupyter notebooks in the browser for easy viewing (GitHub + Jupyter Notebooks = <3).

Getting started with Python and conda

Jupyter notebooks require Python to run. The easiest way to get Python and easily manage Jupyter and the data analysis/scientific packages you will use is through downloading and installing either Anaconda or Miniconda.

While both Anaconda and Miniconda install a version of Python and the conda package and environment manager, Anaconda does more by also installing over 150 of the most popular Python packages for science, math, engineering, and data analysis. The full Anaconda package requires 3 GB of available disk space.

Installing Miniconda

For the sake of time and space, you can download and install Miniconda. This provides the bare minimum to get started with Jupyter. The following steps are from http://conda.pydata.org/docs/install/quick.html.

1. Download Miniconda

Download Miniconda here: https://github.com/blog/1995-github-jupyter-notebooks-3

Be sure to:

  • select the correct installer for your system
  • select the 3.5 version of Python (unless you really want 2.7)

2. Install Miniconda on your system

Mac OS X

  1. Press ⌘+space to open Spotlight Search and type in 'Terminal' and press enter
  2. In the terminal navigate to the location where you downloaded Miniconda, e.g.:
    cd path/to/your/file
    
  3. Type the following and press enter to run, following the prompts:
    bash Miniconda2-latest-MacOSX-x86_64.sh
    
  4. Close and re-open your terminal window for the changes to take effect

Windows

  1. Double click the downloaded .exe file and follow the prompts
  2. If a new terminal window does not open, open a terminal window by clicking Start > Run > Command Prompt

Linux

  1. Open the terminal
  2. In the terminal navigate to the location where you downloaded Miniconda, e.g.:
    cd path/to/your/file
    
  3. Type the following and press enter to run, following the prompts:
    bash Miniconda2-latest-MacOSX-x86_64.sh
    
  4. Close and re-open your terminal window for the changes to take effect

3. Test the installation

To test the installation on any system enter the following command: conda list. If correctly installed, you will see a list of installed packages.

Installing Jupyter and other scientific libraries

Congratulations, you have Python and conda installed. Now you need to use conda to install Jupyter. (If you downloaded Anaconda then you already have all the libraries you need. If you followed the steps above then you will need to download the specific Python libraries you want to use, including Jupyter.)

1. Install Jupyter with conda

In the terminal window run:

conda install jupyter

When prompted, type y and press return to proceed. It may take a little while to install.

2. Install other Python scientific packages with conda

To get started let's download pandas, a data analysis library, and matplotlib, a plotting library.

In the terminal window run:

conda install pandas matplotlib

When prompted, type y and press return to proceed. It may take a little while to install.

You follow the same procedure to install any other Python package, e.g.:

conda install package_name

For a full list of available conda Python packages check the official list here: Available Python packages

Start a Jupyter Notebook

You now have all the dependencies to run a Jupyter notebook and do some computing. To start up a notebook server in the directory you are currently in, run the following in your terminal:

jupyter notebook

A browser window, or a tab in your opened browser, should open displaying the Notebook dashboard:

You will also see some useful information in your terminal telling you the directory in which Jupyter is running, the network address where Jupyter is running, and how to stop Jupyter, e.g.,:

$ Serving notebooks from local directory: /Users/walt/Documents/git-proj/github-public/jupyter-notebooks-intro
$ 0 active kernels 
$ The Jupyter Notebook is running at: http://localhost:8888/
$ Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

Create a new notebook

Use the Notebook dashboard to create a new notebook. In the upper right-hand corner click new and select the type of notebook you would like to create. If you have followed the previous steps, you will have the option to create a Python 3 notebook:

Upload an existing notebook

Follow these steps to download an existing notebook from nbviewer and then uplaod it to your Jupyter Notebook. (The link points you to a notebook about the Jupyter Notebook user interface intended to give you practice using an interactive notebook. This notebook is stored on GitHub and rendered with nbviewer):

  1. Navigate to http://nbviewer.jupyter.org/github/WaltGurley/jupyter-notebooks-intro/blob/master/Jupyter%20-%20interface.ipynb in your browser.
  2. Click the button in the upper right corner to download a web-hosted Jupyter notebook to your machine.
  3. Go back to your Notebook dashboard, click Upload and navigate to the file you just downloaded and click Open.
  4. You should now see 'Jupyter - interface.ipynb' in the dashboard.

Wrap up

You should now have Jupyter running on you local machine with conda and Python, two scientific computing Python packages (pandas and matplotlib), and a notebook.

These are the quick steps to running a notebook server:

  1. In your terminal, navigate to the folder you want to use or contains your notebooks: cd path/to/your/folder
  2. In your terminal, run: jupyter notebook
  3. In the browser, double-click the notebook you want to open, create a new notebook, or upload an existing notebook
  4. When finished using Jupyter, stop the server by pressing control+c in the terminal and following the prompt

Next: To continue to an interactive notebook covering the notebook user interface, in the Notebook dashboard double-click on the notebook uploaded in the last step to open 'Jupyter - interface.ipynb'